package com.gxm.练习.fastjson;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.gxm.模式.干掉if.工厂.Order;
import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 郭训民
 * @description: TODO
 * @title: Demo
 * @projectName jsee
 * @date 2021/7/6 15:44
 */
public class Demo {

    @Test
    public void test01(){
        String jsonMap = "{\"861985910182543360\":{\"billCompanyId\":\"0046\",\"billDeptId\":\"001881\",\"currentDeptId\":\"001881\",\"currentDeptName\":\"丈子头网点\",\"discCompanyId\":\"0045\",\"discDeptId\":\"008579\",\"equallyVoyageId\":\"\",\"forTransfer\":\"16501\",\"linkStatus\":\"\",\"orderId\":\"861985910182543360\",\"orderNo\":\"11460000063\",\"orderStatus\":\"10802\",\"orderType\":\"11301\",\"zsType\":\"68604\"}}";
        String jsonBean = "{\"billCompanyId\":\"0046\",\"billDeptId\":\"001881\",\"currentDeptId\":\"001881\",\"currentDeptName\":\"丈子头网点\",\"discCompanyId\":\"0045\",\"discDeptId\":\"008579\",\"equallyVoyageId\":\"\",\"forTransfer\":\"16501\",\"linkStatus\":\"\",\"orderId\":\"861985910182543360\",\"orderNo\":\"11460000063\",\"orderStatus\":\"10802\",\"orderType\":\"11301\",\"zsType\":\"68604\"}";
        OrderHdr orderHdr = JSON.parseObject(jsonBean, OrderHdr.class);
        Map<String, OrderHdr> map = JSON.parseObject(jsonMap, new TypeReference<HashMap<String, OrderHdr>>(){});
        System.out.println(orderHdr);
        System.out.println(map);
    }

    @Test
    public void test02() {
        for (int i = 0; i < 1000; i++) {
            String listStr = "[1,2,3,4]";
            List<String> strings = JSON.parseArray(listStr, String.class);
            int finalI = i;
            strings.forEach(item -> {
                System.out.println(finalI + ":" + item);
            });
        }
    }

    @Test
    public void test03() {
        List<String> objects = new ArrayList<>();
        objects.add("a");
        objects.add("b");
        objects.add("c");
        objects.forEach(item -> {
            if (item.equals("b")) {
                return;
            }
            System.out.println(item);
        });
    }

    @Test
    public void test04() {
        String arr = "[{\"name\":\"张三\",\"age\":\"12\"}]";
        List<Map> maps = JSON.parseArray(arr, Map.class);
        System.out.println(maps);
    }

    @Test
    public void test05() {
        Map<String, String> map = new HashMap<>();
        map.put("a", "a");
        map.put("b", "b");
        map.put("c", "c");
        System.out.println(map.keySet().toArray()[0]);
    }

    @Test
    public void test06() {
        Long l = 100L;
        Long num = 3L;
        System.out.println(l / num);

        String str = "[{\"name\":\"货品\",\"product_type_name\":\"品类1>二级品类1\",\"product_other_price\":\"10.00\",\"specification\":\"规格1\",\"product_id\":2349,\"product_batch\":\"CG240129000009\",\"product_price\":\"12.10\",\"product_nums\":\"2.000\",\"allMoney\":\"34.20\"}]\n";
    }
}
